<?php
namespace common\models\store;

use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
use common\enums\StatusEnum;
use common\helpers\RegularHelper;

class Store extends ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%store}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
//            [['name', 'address'], 'required', 'on' => ['create']],
            [['member_id', 'provinces', 'city', 'area', 'status', 'created_at', 'updated_at'], 'integer'],
            [['money', 'accumulate_money', 'frozen_money'], 'number'],
            [['name','telephone'], 'string', 'max' => 20],
            ['leader','string','max'=>40],
            [['logo', 'picture', 'address_name','address_detail','business_lincese'], 'string', 'max' => 150],
            [['business_time'], 'string', 'max' => 100],
//            ['mobile', 'match', 'pattern' => RegularHelper::mobile(),'message' => '不是一个有效的手机号码'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'member_id' => '账号ID',
            'name' => '店铺名称',
            'logo' => 'logo图片',
            'picture' => '门店图片',
            'business_time' => '营业时间',
            'telephone' => '客服电话',
            'money' => '余额',
            'accumulate_money' => '累计金额',
            'frozen_money' => '冻结金额',
            'user_integral' => '积分',
            'provinces' => '省',
            'city' => '市',
            'area' => '区',
            'address_name'=>'地址',
            'address_detail'=>'具体地址',
            'attestation'=>'是否认证',
            'status' => '状态',
            'leader' => '负责人',
            'business_lincese' => '营业执照',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
        ];
    }

    /**
     * 场景
     *
     * @return array
     */
    public function scenarios()
    {
        return [
//            'create' => [''],
//            'backendCreate' => ['username', 'password_hash'],
            'default' => array_keys($this->attributeLabels()),
        ];
    }

//    /**
//     * 关联第三方绑定
//     */
//    public function getAuth()
//    {
//        $this->hasMany(MemberAuth::class, ['member_id' => 'id'])->where(['status' => StatusEnum::ENABLED]);
//    }


    /**
     * @return array
     */
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::class,
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ],
            ],
        ];
    }
}
